package com.ruoyi.demo.controller;

import java.util.List;
import java.util.Arrays;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.demo.dto.TaskDataDto;
import com.ruoyi.demo.vo.TaskDataVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.demo.domain.ReportDeviceData;
import com.ruoyi.demo.service.IReportDeviceDataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备数据Controller
 * 
 * @author shc
 * @date 2025-08-13
 */
@RestController
@RequestMapping("/reportDeviceData")
public class ReportDeviceDataController extends BaseController {
    @Autowired
    private IReportDeviceDataService reportDeviceDataService;

    /**
     * 查询设备数据列表
     */
    @PreAuthorize("@ss.hasPermi('demo:reportDeviceData:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReportDeviceData reportDeviceData) {
        startPage();
        List<ReportDeviceData> list = reportDeviceDataService.selectReportDeviceDataList(reportDeviceData);
        return getDataTable(list);
    }

    /**
     * 导出设备数据列表
     */
    @PreAuthorize("@ss.hasPermi('demo:reportDeviceData:export')")
    @Log(title = "设备数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReportDeviceData reportDeviceData) {
        List<ReportDeviceData> list = reportDeviceDataService.selectReportDeviceDataList(reportDeviceData);
        ExcelUtil<ReportDeviceData> util = new ExcelUtil<ReportDeviceData>(ReportDeviceData.class);
        util.exportExcel(response, list, "设备数据数据");
    }

    /**
     * 获取设备数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('demo:reportDeviceData:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(reportDeviceDataService.getById(id));
    }

    /**
     * 新增设备数据
     */
    @PreAuthorize("@ss.hasPermi('demo:reportDeviceData:add')")
    @Log(title = "设备数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReportDeviceData reportDeviceData) {
        return toAjax(reportDeviceDataService.save(reportDeviceData));
    }

    /**
     * 修改设备数据
     */
    @PreAuthorize("@ss.hasPermi('demo:reportDeviceData:edit')")
    @Log(title = "设备数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReportDeviceData reportDeviceData) {
        return toAjax(reportDeviceDataService.updateById(reportDeviceData));
    }

    /**
     * 删除设备数据
     */
    @PreAuthorize("@ss.hasPermi('demo:reportDeviceData:remove')")
    @Log(title = "设备数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(reportDeviceDataService.removeByIds(Arrays.asList(ids)));
    }
    @GetMapping("/keepLatestReportPower")
    public AjaxResult getSnRankApi(@RequestParam("sn") String sn) {
        if (StringUtils.isEmpty(sn)) {
            return AjaxResult.error("sn传参为空");
        }
      return toAjax(reportDeviceDataService.keepLatestReportPower(sn));

    }
}
